package com.jr.interceptors;

import com.jr.entity.User;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class LoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //是否登录正确的判断
        User user = (User)request.getSession().getAttribute("user");
        HttpSession session = request.getSession();
        if (user == null) {

            //跳转登录页面

            response.sendRedirect(request.getContextPath()+"/login.jsp");
            return false;
        }

        if(user.getUname()==null||user.getUphone()==null||user.getUemail()==null){
            session.setAttribute("flag","false");
            return true;
        }

        //放行通过
        return true;
    }
}